#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)

AC_INIT([nautilus-nutstore], [0.1.0], [bug-report@nutstore.net])

AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)

AC_PREFIX_DEFAULT(/usr)

AC_CONFIG_HEADER([config.h])
#AM_CONFIG_HEADER(config.h)

# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL

# Check for pkg-config
PKG_PROG_PKG_CONFIG([0.10])

# Dependency checks
GLIB_REQUIRED=2.0.0
NAUTILUS_REQUIRED=2.0.0

PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $GLIB_REQUIRED])
PKG_CHECK_MODULES([NAUTILUS], [libnautilus-extension >= $NAUTILUS_REQUIRED])

# Make dependency CFLAGS and LIBS available
AC_SUBST(NAUTILUS_CFLAGS)
AC_SUBST(NAUTILUS_LIBS)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

# lol stolen from the automake manual
AC_ARG_ENABLE([debug],
    [  --enable-debug    Turn on debugging],
    [case "${enableval}" in
        yes) debug=true ;;
        no)  debug=false ;;
        *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
    esac],
    [debug=false])
AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])

# Get nautilus extensions directory
AC_ARG_WITH(nautilus-extension-dir,
    [AS_HELP_STRING([--with-nautilus-extension-dir],
    [specify the nautilus extension directory])])

AC_MSG_CHECKING([for nautilus extension directory])
if test -n "$with_nautilus_extension_dir"; then
    NAUTILUS_EXTENSION_DIR=$with_nautilus_extension_dir
else
    NAUTILUS_EXTENSION_DIR=`$PKG_CONFIG --variable=extensiondir libnautilus-extension`
fi

if test -z "$NAUTILUS_EXTENSION_DIR"; then
    NAUTILUS_EXTENSION_DIR='${exec_prefix}/lib/nautilus/extension-1.0'
fi

AC_MSG_RESULT([${NAUTILUS_EXTENSION_DIR}])
AC_SUBST(NAUTILUS_EXTENSION_DIR)

NAUTILUS_VERSION=`$PKG_CONFIG --modversion libnautilus-extension`
if test -n "$NAUTILUS_VERSION"; then
    NAUTILUS_VERSION_MAJOR=`echo -n $NAUTILUS_VERSION | cut -d . -f 1` 
    NAUTILUS_VERSION_MINOR=`echo -n $NAUTILUS_VERSION | cut -d . -f 2`
    NAUTILUS_VERSION_MICRO=`echo -n $NAUTILUS_VERSION | cut -d . -f 3`
fi

AC_DEFINE_UNQUOTED(NAUTILUS_VERSION_MAJOR, [$NAUTILUS_VERSION_MAJOR], [ nautilus version major])
AC_DEFINE_UNQUOTED(NAUTILUS_VERSION_MINOR, [$NAUTILUS_VERSION_MINOR], [ nautilus version minor])
AC_DEFINE_UNQUOTED(NAUTILUS_VERSION_MICRO, [$NAUTILUS_VERSION_MICRO], [ nautilus version micro])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_TIME

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([memset select socket strchr strdup strtol])

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 icons/Makefile
                 icons/hicolor/Makefile
                 icons/hicolor/16x16/Makefile
                 icons/hicolor/64x64/Makefile
                 icons/hicolor/16x16/apps/Makefile
                 icons/hicolor/64x64/emblems/Makefile
                 icons/hicolor/64x64/apps/Makefile])
AC_OUTPUT
